package com.caesar.PracticeCompare;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author caesar
 * @date 2025/7/12
 * @Description:
 * @apiNote
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Rectangle implements Comparable{
    private double length;
    private double width;
    public double area(){
        return length * width;
    }
    public double perimeter(){
        return 2 * (length + width);
    }

    @Override
    public String toString() {
        return "长：" + length +
                "， 宽：" + width +
                "，面积：" + area()
                +"，周长：" + perimeter();
    }

    @Override
    public int compareTo(Object o) {
        Rectangle r = (Rectangle) o;
        int result = Double.compare(this.area(),r.area());
        return result != 0 ? result : Double.compare(this.length,r.length);
    }
}
